function checkUser_Ins()
{
	
	var userID = document.getElementById("userID").value;
	if(userID=="")
	  {alert("please input userid");return false;}
	if(!/^\d+$/.test(userID))
	  {alert('userID is illegal');return false;}
	if(userID.length!=8)
	  {alert('userID length is illegal,8 bits');return false;}
	
	var barcode = document.getElementById("barcode").value;

	if(barcode==""){
		alert("please enter barcode");
		return false;
	}
	if(barcode.length>45){
		alert("barcode is too long");
		return false;
	}
	if(!/^\d+$/.test(barcode))
	{
		alert('barcode is illegal,number is ok');
	    return false;
	}
	var selectdays = document.getElementById("selectdays").value;
	var days = document.getElementById("days").value;
	
	if(""!=days)
	{
		if(!/^([1-9]|[1-9]\d|100)$/.test(days))
		{
			alert("oops,the range of days is from 1 - 100");
			return;
		}
		borrow(userID,barcode,days);
	}else
	{
		borrow(userID,barcode,selectdays);
	}
}
function borrow(userID,barcode,days)
{
	var xmlHttp = new XMLHttpRequest();
	
	if(window.ActiveXObject)
	{
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		
	}else if(window.XMLHttpRequest)
	{
		xmlHttp = new XMLHttpRequest();
		
	}else
	{
		alert("Ajax won't show in your web browser ");
		return;
	}
	xmlHttp.open("GET","BorrowServlet?userID="+userID +"&barcode=" + barcode + "&days=" + days,true);
	
	xmlHttp.onreadystatechange = function()
	{
	
		if(xmlHttp.readyState==4 && xmlHttp.status==200)
		{
			var login=/<script>/ig;
			if(login.test(xmlHttp.responseText))
			{
				eval("top.location.href='/lab/login.jsp'");
				return;
			}
			var contentType=xmlHttp.getResponseHeader("Content-Type");
			
			if(contentType=="text/html")
			{
				var message = xmlHttp.responseText;
				document.getElementById("message").innerHTML= message;
				document.getElementById("firstname").value ="";
				document.getElementById("lastname").value ="";
				document.getElementById("gender").value ="";
				document.getElementById("email").value ="";
				document.getElementById("days").value ="";
				document.getElementById("borrowbody").innerHTML=
				" <table width='100%' border='1px' cellpadding='0' cellspacing='0' bordercolor='#8D8D8D' bgcolor='#FFFFFF'>"+
				"  <tr align='center' bgcolor='#F9D16B'>"+
                "   <td width='20%' height='25'>Instrument Name</td>"+
                "   <td width='15%'>Bar-code</td>"+
                "   <td width='15%'>User ID</td>"+
                "   <td width='15%'>Borrow Time</td>"+
                "   <td width='15%'>Back Time</td>"+
                " </tr>"+
                " <tr>"+
                "  <td align='center' height='25' style='padding:5px;'>&nbsp;</td>"+
                "  <td align='center' style='padding:5px;'>&nbsp;</td>"+
                "  <td align='center' style='padding:5px;'>&nbsp;</td>"+
                "  <td align='center' style='padding:5px;'>&nbsp;</td>"+
                "  <td align='center' id = 'backtime'>&nbsp;</td>"+
                " </tr>"+
                " </table>";
			}
			if(contentType=="application/json")
			{
				var jsonStr= xmlHttp.responseText;
				var jsonArray = eval('(' + jsonStr + ')');
				document.getElementById("userID").value = jsonArray[0].userID;
				document.getElementById("barcode").value = jsonArray[0].barcode;
				document.getElementById("firstname").value = jsonArray[0].firstname;
				document.getElementById("lastname").value = jsonArray[0].lastname;
				document.getElementById("gender").value = jsonArray[0].gender;
				document.getElementById("email").value = jsonArray[0].email;
				
				var trs = 
					" <table width='100%' border='1px' cellpadding='0' cellspacing='0' bordercolor='#8D8D8D' bgcolor='#FFFFFF'>"+
					"  <tr align='center' bgcolor='#F9D16B'>"+
	                "   <td width='20%' height='25'>Instrument Name</td>"+
	                "   <td width='15%' height='25'>Bar-code</td>"+
	                "   <td width='15%'>User ID</td>"+
	                "   <td width='15%'>Borrow Time</td>"+
	                "   <td width='15%'>Back Time</td>"+
	                " </tr>";
					for(var i = 0; i < jsonArray.length; i++)
					{
						var jsonObj = jsonArray[i];
						trs = trs +
						 " <tr>"+
			             "  <td align='center' height='25' style='padding:5px;'>"+ jsonObj.insName +"</td>"+
			             "  <td align='center' height='25' style='padding:5px;'>"+ jsonObj.barcode +"</td>"+
		                 "  <td align='center' style='padding:5px;'>"+ jsonObj.userID +"</td>"+
		                 "  <td align='center' style='padding:5px;'>"+ jsonObj.borrowDate +"</td>"+
		                 "  <td align='center' id = 'backtime'>"+ jsonObj.SBackDate +"</td>"+
		                 " </tr>";
					}
					trs = trs+"</table>";
					document.getElementById("borrowbody").innerHTML = trs;
					document.getElementById("message").innerHTML = "SUCCESS!";
			}
		}
		else	
		{
			document.getElementById("message").innerHTML = "doing..."
		}
	
	}
	xmlHttp.send(null);
	
	
	
}
